require "vector"
require "std"

function d6()
  local object={}

  -- every object needs a mass, angular mass, position, angular velocity, etc, etc.
  object.position=Vector{0,0,0}
  object.mass=1
  object.velocity=Vector{0,0,0}
  object.angularMass=5
  object.angularVelocity=Vector{0,0,0}
  object.color=0xFFFF00
  object.radius=0.8
  
  -- every object has a list of vertices that take part in the physics simulation.
  object.vertices={
    {1,-1,-1},{1,1,-1},{-1,1,-1},{-1,-1,-1},
    {1,-1,1},{1,1,1},{-1,1,1},{-1,-1,1}
  }
  table.transform(object.vertices, Vector)
  --we also rescale the d6 because it's too big
  table.transform(object.vertices, func.pbind(__mul,0.5))  

  
  
  -- every object has a set of surfaces that hold the polygons and the textures
  local polygons=verticesToPolygons(object.vertices)
  object.surfaces=table.transform(polygons,polygonToSurface)
  
  --every surface also has a texture that contains the number image.
  for i,surface in ipairs(object.surfaces) do
    surface.texture={
      image=i..".png",
      o=surface.center,
      x=math.avg(surface.polygon[1], surface.polygon[2], surface.center),
      y=math.avg(surface.polygon[3], surface.polygon[2], surface.center)
    }
  end
  
  -- every object also has a set of vectors that need to be updated with rotation.
  object.allVertices=extractAllVertices(object)

  -- also surfaces refer back to their parent object
  for i,surface in ipairs(object.surfaces) do 
    surface.object=object
  end
  
return object end
